package com.hong.spring.log4j;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

/**
 * @Auther: csh
 * @Date: 2020/7/29 15:58
 * @Description:通过java读取配置文件
 */
public class SimpleXmiLog4j {
    public static void main(String[] args)  throws Exception{
        //TODO 注意该路基在每台电脑上面可能不一样！
        File file  =new File("D:\\ideaWorkSpace\\spring\\src\\main\\resources\\log4j\\simple-log4j.xml");
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
        final ConfigurationSource source = new ConfigurationSource(in);
        Configurator.initialize(null, source);
        Logger logger = LogManager.getLogger("myLogger");
        logger.trace("trace message");
        logger.debug("debug message");
        logger.info("info message");
        logger.warn("warn message");
        logger.error("error message");
        logger.fatal("fatal message");
    }
}
